import 'package:equatable/equatable.dart';
import 'package:backend.purchases/domain/entities/yookassa_api/payments/yookassa_api_payment_cancellation_reason.dart';

const kYookassaApiPaymentCancellationThreeDSecureFailedReasonValue = '3_d_secure_failed';
const kYookassaApiPaymentCancellationCallIssuerReasonValue = 'call_issuer';
const kYookassaApiPaymentCancellationCanceledByMerchantReasonValue = 'canceled_by_merchant';
const kYookassaApiPaymentCancellationCardExpiredReasonValue = 'card_expired';
const kYookassaApiPaymentCancellationCountryForbiddenReasonValue = 'country_forbidden';
const kYookassaApiPaymentCancellationExpiredOnConfirmationReasonValue = 'expired_on_confirmation';
const kYookassaApiPaymentCancellationFraudSuspectedReasonValue = 'fraud_suspected';
const kYookassaApiPaymentCancellationGeneralDeclineReasonValue = 'general_decline';
const kYookassaApiPaymentCancellationInsufficientFundsReasonValue = 'insufficient_funds';
const kYookassaApiPaymentCancellationInternalTimeoutReasonValue = 'internal_timeout';
const kYookassaApiPaymentCancellationInvalidCardNumberReasonValue = 'invalid_card_number';
const kYookassaApiPaymentCancellationInvalidCscReasonValue = 'invalid_csc';
const kYookassaApiPaymentCancellationIssuerUnavailableReasonValue = 'issuer_unavailable';
const kYookassaApiPaymentCancellationPaymentMethodLimitExceededReasonValue =
    'payment_method_limit_exceeded';
const kYookassaApiPaymentCancellationPaymentMethodRestrictedReasonValue =
    'payment_method_restricted';
const kYookassaApiPaymentCancellationPermissionRevokedReasonValue = 'permission_revoked';

class YookassaApiPaymentCancellationReasonDto extends Equatable {
  const YookassaApiPaymentCancellationReasonDto._internal({
    required this.reasonString,
  });

  final String reasonString;

  @override
  List<Object?> get props {
    return [
      reasonString,
    ];
  }

  factory YookassaApiPaymentCancellationReasonDto.fromString(String reasonString) {
    return YookassaApiPaymentCancellationReasonDto._internal(
      reasonString: reasonString,
    );
  }

  YookassaApiPaymentCancellationReason toYookassaApiPaymentCancellationReason() {
    if (reasonString == kYookassaApiPaymentCancellationThreeDSecureFailedReasonValue) {
      return YookassaApiPaymentCancellationReason.threeDSecureFailed;
    }

    if (reasonString == kYookassaApiPaymentCancellationCallIssuerReasonValue) {
      return YookassaApiPaymentCancellationReason.callIssuer;
    }

    if (reasonString == kYookassaApiPaymentCancellationCanceledByMerchantReasonValue) {
      return YookassaApiPaymentCancellationReason.canceledByMerchant;
    }

    if (reasonString == kYookassaApiPaymentCancellationCardExpiredReasonValue) {
      return YookassaApiPaymentCancellationReason.cardExpired;
    }

    if (reasonString == kYookassaApiPaymentCancellationCountryForbiddenReasonValue) {
      return YookassaApiPaymentCancellationReason.countryForbidden;
    }

    if (reasonString == kYookassaApiPaymentCancellationExpiredOnConfirmationReasonValue) {
      return YookassaApiPaymentCancellationReason.expiredOnConfirmation;
    }

    if (reasonString == kYookassaApiPaymentCancellationFraudSuspectedReasonValue) {
      return YookassaApiPaymentCancellationReason.fraudSuspected;
    }

    if (reasonString == kYookassaApiPaymentCancellationGeneralDeclineReasonValue) {
      return YookassaApiPaymentCancellationReason.generalDecline;
    }

    if (reasonString == kYookassaApiPaymentCancellationInsufficientFundsReasonValue) {
      return YookassaApiPaymentCancellationReason.insufficientFunds;
    }

    if (reasonString == kYookassaApiPaymentCancellationInternalTimeoutReasonValue) {
      return YookassaApiPaymentCancellationReason.internalTimeout;
    }

    if (reasonString == kYookassaApiPaymentCancellationInvalidCardNumberReasonValue) {
      return YookassaApiPaymentCancellationReason.invalidCardNumber;
    }

    if (reasonString == kYookassaApiPaymentCancellationInvalidCscReasonValue) {
      return YookassaApiPaymentCancellationReason.invalidCsc;
    }

    if (reasonString == kYookassaApiPaymentCancellationIssuerUnavailableReasonValue) {
      return YookassaApiPaymentCancellationReason.issuerUnavailable;
    }

    if (reasonString == kYookassaApiPaymentCancellationPaymentMethodLimitExceededReasonValue) {
      return YookassaApiPaymentCancellationReason.paymentMethodLimitExceeded;
    }

    if (reasonString == kYookassaApiPaymentCancellationPaymentMethodRestrictedReasonValue) {
      return YookassaApiPaymentCancellationReason.paymentMethodRestricted;
    }

    if (reasonString == kYookassaApiPaymentCancellationPermissionRevokedReasonValue) {
      return YookassaApiPaymentCancellationReason.permissionRevoked;
    }

    throw UnimplementedError();
  }
}
